﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;



namespace nERP.ViewModel.Bas.CodingRuleVMs
{
    public partial class CodingRuleCodingListDetailListVM : BasePagedListVM<CodingRule, CodingRuleDetailSearcher>
    {
        
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("CodingRule", GridActionStandardTypesEnum.AddRow, "新建","", dialogWidth: 800),
                this.MakeStandardAction("CodingRule", GridActionStandardTypesEnum.RemoveRow, "删除","", dialogWidth: 800),
            };
        }
 
        protected override IEnumerable<IGridColumn<CodingRule>> InitGridHeader()
        {
            return new List<GridColumn<CodingRule>>{
                
                this.MakeGridHeader(x => x.ID).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.ID"].Value),
                this.MakeGridHeader(x => x.CreateTime).SetEditType(EditTypeEnum.Datetime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.UpdateTime).SetEditType(EditTypeEnum.Datetime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.CreateBy).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.UpdateBy).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.IsValid).SetEditType(EditTypeEnum.ComboBox,Utils.GetBoolCombo(BoolComboTypes.YesNo, selectText:Wtm.Localizer?["Sys.PleaseSelect"])).SetTitle(@Localizer["_Admin.IsValid"].Value),
                this.MakeGridHeader(x => x.Seq).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.CodeRule).SetEditType(EditTypeEnum.ComboBox,typeof(CodeRuleEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.规则"].Value),
                this.MakeGridHeader(x => x.FixedValue).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.固定值"].Value),
                this.MakeGridHeader(x => x.FixedRule).SetEditType(EditTypeEnum.ComboBox,typeof(FixedEnum).ToListItems(null,true)).SetTitle(@Localizer["Page.规则值"].Value),
                this.MakeGridHeader(x => x.GlideLen).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.流水号长度"].Value),
                this.MakeGridHeader(x => x.StartNumber).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.流水号起始值"].Value),
                this.MakeGridHeader(x => x.GlideStep).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.递增步长"].Value),
                this.MakeGridHeader(x => x.Glide).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.流水号补位码"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<CodingRule> GetSearchQuery()
        {
                
            var id = (string)Searcher.CodingListId.ConvertValue(typeof(string));
            if (id == null)
                return new List<CodingRule>().AsQueryable().OrderBy(x => x.ID);
            var query = DC.Set<CodingRule>()
                .Where(x => id == x.CodingListId)

                .OrderBy(x => x.ID);
            return query;
        }

    }

    public partial class CodingRuleDetailSearcher : BaseSearcher
    {
        
        [Display(Name = "_Model._CodingRule._CodingList")]
        public string CodingListId { get; set; }
    }

}

